<template>
  <div class="app-container">
    <el-dialog :title="'详情（'+form.orderNo+'）'" :visible.sync="dialogVisible" width="60%" append-to-body>
      <el-form ref="form" :model="form" v-loading="loading">
        <div style="display: flex;align-items: center;">
          <div class="myTitle">基本信息</div>
          <dict-tag :options="dict.type.sys_order_type" :value="form.orderType" style="margin-left: 10px"/>
          <dict-tag :options="dict.type.ims_order_status" :value="form.status" style="margin-left: 10px"/>
        </div>
        <el-row :gutter="10">
          <el-col :span="6">
            <el-form-item label="订单编号" prop="orderNo">
              <div>{{ form.orderNo }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="下单日期" prop="createTime">
              <div>{{ form.createTime }}</div>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="来源平台" prop="orderFrom">
              <dict-tag :options="dict.type.ims_source_platform" :value="form.orderFrom"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="源平台单号" prop="sourceOrderNo">
              <div>{{ form.sourceOrderNo }}</div>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="6" v-if="form.orderType==10">
            <el-form-item label="生产方式" prop="productFrom">
              <dict-tag :options="dict.type.basic_good_source" :value="form.productFrom"/>
            </el-form-item>
          </el-col>
          <el-col :span="6" v-if="form.orderType==10">
            <el-form-item label="加急单" prop="urgent">
              <dict-tag :options="dict.type.sys_yes_no" :value="form.urgent"/>
            </el-form-item>
          </el-col>
          <el-col :span="6" v-if="form.orderType==10">
            <el-form-item label="样稿图片" prop="imageUrl">
              <div style="display: flex">
                <el-image
                  style="width: 150px;height: 150px"
                  v-if="form.imageUrl"
                  :src="form.imageUrl"
                  fit="contain"
                  :preview-src-list="[form.imageUrl]"
                >
                </el-image>
                <div v-else>暂无</div>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="6" v-if="form.orderType==10">
            <el-form-item label="设计图纸" prop="fileUrl">
              <div style="display: flex">
                <el-link type="primary" v-if="form.fileUrl" @click="downloadFile(form.fileUrl)">{{ form.fileName }}
                </el-link>
                <div v-else>暂无</div>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
        <div class="myTitle" v-if="form.orderType==10">定制信息</div>
        <el-row :gutter="10" style="display: flex;flex-wrap: wrap;">
          <el-col :span="6" v-for="(key,value) in form.skuDescCn">
            <el-form-item :label="value">
              {{ key }}
            </el-form-item>
          </el-col>
        </el-row>
        <div v-if="form.orderType==10">
          <div class="myTitle">配件信息</div>
          <el-table
            :data="form.matPartProductVos"
            max-height="500"
          >
            <el-table-column type="index" label="序号" align="center"/>
            <el-table-column prop="imageUrl" label="图片" align="center">
              <template slot-scope="scope">
                <div v-if="!scope.row.imageUrl">暂无</div>
                <el-image
                  v-else
                  style="width: 80px;height: 80px"
                  :src="scope.row.imageUrl"
                  fit="contain"
                  :preview-src-list="[scope.row.imageUrl]"
                >
                </el-image>
              </template>
            </el-table-column>
            <el-table-column prop="productName" label="配件名称" align="center"/>
            <el-table-column prop="skuName" label="规格名称" align="center"/>
            <el-table-column prop="unitPrice" label="单价(元)" align="center"/>
            <el-table-column prop="quantity" label="数量" align="center"/>
          </el-table>
        </div>
        <div v-if="form.orderType==20">
          <div class="myTitle">商品信息</div>
          <el-table
            :data="form.matPartProductVos"
            max-height="500"
          >
            <el-table-column type="index" label="序号" align="center"/>
            <el-table-column prop="imageUrl" label="图片" align="center">
              <template slot-scope="scope">
                <div v-if="!scope.row.imageUrl">暂无</div>
                <el-image
                  v-else
                  style="width: 80px;height: 80px"
                  :src="scope.row.imageUrl"
                  fit="contain"
                  :preview-src-list="[scope.row.imageUrl]"
                >
                </el-image>
              </template>
            </el-table-column>
            <el-table-column prop="title" label="商品/套餐名称" align="center"/>
            <el-table-column prop="skuName" label="商品规格" align="center"/>
            <el-table-column prop="priceType" label="类型" align="center" width="100px">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.ats_price_type" :value="scope.row.priceType"/>
              </template>
            </el-table-column>
            <el-table-column prop="unitPrice" label="单价(元)" align="center" width="100px"/>
            <el-table-column prop="quantity" label="数量" align="center" width="100px"/>
            <el-table-column prop="fileUrl" label="附件" align="center" width="100px">
              <template slot-scope="scope">
                <el-link v-if="scope.row.fileUrl" type="primary" @click="downloadFile(scope.row.fileUrl)">附件</el-link>
                <div v-else>-</div>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div>
          <div class="myTitle">收件人信息</div>
          <el-row :gutter="10">
            <el-col :span="6">
              <el-form-item label="快递公司" prop="expressName">
                <div>{{ form.expressName }}</div>
              </el-form-item>
            </el-col>
            <el-col :span="16">
              <el-form-item label="收件人信息" prop="recipientContent">
                <div>{{ form.recipientContent }}</div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="10">
            <el-col :span="6">
              <el-form-item label="姓名" prop="recipient">
                <div>{{ form.recipient || '-' }}</div>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="电话" prop="recipientTel">
                <div>{{ form.recipientTel || '-' }}</div>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="详细地址" prop="fullName">
                <div>{{ form.fullName || '-' }}</div>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
        <div>
          <div class="myTitle">付款信息</div>
          <el-row :gutter="10">
            <el-col :span="6">
              <el-form-item label="商品价格(元)" prop="goodsPrice">
                <div>{{ form.goodsPrice }}</div>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="配件价格(元)" prop="matPartPrice">
                <div>{{ form.matPartPrice }}</div>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="快递价格(元)" prop="expressPrice">
                <div>{{ form.expressPrice }}</div>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="其它费用(元)" prop="otherPrice">
                <div>{{ form.otherPrice }}</div>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="合计(元)" prop="totalPrice">
                <div>{{ form.totalPrice }}</div>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
        <el-row :gutter="10">
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <div>{{ form.remark || '-' }}</div>
            </el-form-item>
          </el-col>
        </el-row>
        <div v-if="type">
          <div class="myTitle">审核信息</div>
          <el-row :gutter="10">
            <el-col :span="8">
              <el-form-item label="审核结果" prop="event" required>
                <el-select v-model="form.event" filterable style="width: 100%">
                  <el-option
                    v-for="item in dict.type.sys_approve_result"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="16">
              <el-form-item label="审核意见" prop="reviewDesc" :required="form.result==1">
                <el-input type="textarea" v-model="form.reviewDesc" placeholder="请输入"/>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible=false">取 消</el-button>
        <el-button type="primary" v-if="type" @click="dialogOk">审 核</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  approveOrder,
  getCustomOrder,
} from "../../../api/imsMng";

export default {
  dicts: ['ims_order_status', 'ims_source_platform', 'basic_good_source', 'sys_yes_no', 'sys_approve_result', 'ats_price_type', 'sys_order_type'],
  data() {
    return {
      type: 0,//0详情，1审核
      loading: false,
      dialogVisible: false,
      form: {}
    }
  },
  //orderType:10定制，20现货
  methods: {
    show(form, type) {
      this.type = type
      this.dialogVisible = true
      this.form = {}
      this.resetForm('form')
      this.getOrderDetail(form.id)
    },
    getOrderDetail(id) {
      this.loading = true
      getCustomOrder(id).then(res => {
        this.form = res.data
        this.form.orderType = 20
        this.form.skuDescCn = JSON.parse(this.form.skuDescCn)
      }).finally(e => {
        this.loading = false
      })
    },
    downloadFile(url) {
      window.open(url)
    },
    dialogOk() {
      this.$refs.form.validate(e => {
        if (e) {
          let req = {
            id: this.form.id,
            event: this.form.event,
            reviewDesc: this.form.reviewDesc
          }
          this.loading = true
          approveOrder(req).then(res => {
            this.$emit('ok')
            this.dialogVisible = false
            this.$message.success('审核成功')
          }).finally(e => {
            this.loading = false
          })
        }
      })
    }
  }
}
</script>
